package com.ruoyi.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.Angle;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysWechatConfig;
import com.ruoyi.project.system.service.ISysWechatConfigService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 微信小程序配置Controller
 *
 * @author hongwj
 * @date 2024-02-06
 */
@RestController
@RequestMapping("/system/wechatConfig" )
@Slf4j
public class SysWechatConfigController extends BaseController {
    @Autowired
    private ISysWechatConfigService sysWechatConfigService;

    /**
     * 查询微信小程序配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechatConfig:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(SysWechatConfig sysWechatConfig) {
        startPage();
        List<SysWechatConfig> list = sysWechatConfigService.selectSysWechatConfigList(sysWechatConfig);
        return getDataTable(list);
    }

    /**
     * 查询所有微信小程序配置列表
     */
    @Log(title = "微信小程序配置" , businessType = BusinessType.OTHER)
    @GetMapping("/all/wechatConfigs" )
    @Anonymous
    public AjaxResult all(SysWechatConfig sysWechatConfig) {
        List<SysWechatConfig> list = sysWechatConfigService.selectSysWechatConfigList(sysWechatConfig);
        return success(list);
    }

    /**
     * 导出微信小程序配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechatConfig:export')" )
    @Log(title = "微信小程序配置" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, SysWechatConfig sysWechatConfig) {
        List<SysWechatConfig> list = sysWechatConfigService.selectSysWechatConfigList(sysWechatConfig);
        ExcelUtil<SysWechatConfig> util = new ExcelUtil<SysWechatConfig>(SysWechatConfig. class);
        util.exportExcel(response, list, "微信小程序配置数据" );
    }

    /**
     * 获取微信小程序配置详细信息
     */
    @GetMapping(value = "/{id}" )
    @Anonymous
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(sysWechatConfigService.selectSysWechatConfigById(id));
    }

    /**
     * 新增微信小程序配置
     */
    @PreAuthorize("@ss.hasPermi('system:wechatConfig:add')" )
    @Log(title = "微信小程序配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWechatConfig sysWechatConfig) {
        return toAjax(sysWechatConfigService.insertSysWechatConfig(sysWechatConfig));
    }

    /**
     * 修改微信小程序配置
     */
    @PreAuthorize("@ss.hasPermi('system:wechatConfig:edit')" )
    @Log(title = "微信小程序配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWechatConfig sysWechatConfig) {
        return toAjax(sysWechatConfigService.updateSysWechatConfig(sysWechatConfig));
    }

    /**
     * 删除微信小程序配置
     */
    @PreAuthorize("@ss.hasPermi('system:wechatConfig:remove')" )
    @Log(title = "微信小程序配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysWechatConfigService.deleteSysWechatConfigByIds(ids));
    }
}
